#pragma once
#ifndef GRAPHICS_MANAGER_H
#define GRAPHICS_MANAGER_H
#include "Base.h"
#include "Engine\Engine_Def.h"
#include <d3dx9.h>
#include "Graphics_Def.h"
#include "Camera\Object3D.h"
#include "Camera\Frustum.h"
#include "Math/Vector3.h"
class CCamera;

class CGraphicsManager
{
	public:
		CGraphicsManager							(void): m_pD3D(0), 
													m_bPaintSolid(true),
													m_BackbufferColor_release(colBLACK),
													m_BackbufferColor_debug(colGREY),
													m_uWidth(0), m_uHeight(0), m_PosX(0), m_Speed(1), m_Yaw(0), m_Pos(Vect3f(1,1,1))
													{}
		~CGraphicsManager							(void);
		void				Init					(HWND hWnd, const SEngineInitParams& params);
		void				DeInit					();
		void				Render					(float l_DeltaTime);
		void				Update					(float l_DeltaTime);
		void				BeginRendering			();
		void				SetupMatrices			(CCamera *camera);
		void				EndRendering			();
		void				EnableZBuffering		();
		void				DisableZBuffering		();
		void				EnableAlphaBlend		();
		void				DisableAlphaBlend		();
		void				SetSolidPaintMode		(bool l_SolidMode);
		void				ChangeSolidPaintMode	();
		void				Debug_DrawLine			(const Vect3f &PosA, const Vect3f &PosB, CColor Color);
		void				Debug_DrawAxis			(float size);
		void				Debug_DrawGrid			(float size, uint8 numlines, CColor color);
		void				Debug_DrawGrid			(float sizeW, float sizeH, uint8 numlines, CColor color);
		void				Debug_DrawCube			(float size, CColor color);
		void				Debug_DrawSphere		(float r, int slices, CColor color);
		void				SetTransform			(const Mat44f& m);
		LPDIRECT3DDEVICE9	GetDevice				() {return m_pD3DDevice;}
		uint16				GetWidth				() {return m_uWidth;}
		uint16				GetHeigth				() {return m_uHeight;}
		void   				DrawRectangle2D			(const Vect2i& pos, uint32 w, uint32 h, const CColor backGroundColor, uint32 edge_w, uint32 edge_h, const CColor edgeColor );
		void				DrawCamera				(CCamera* camera);
		bool				SphereVisible			( const Vect3f &p, float radius );
		//----QuadRender Functions----------------------------------------------
		void   				DrawQuad2D   			(const Vect2i& pos, uint32 w, uint32 h, ETypeAlignment alignment, CColor color = colBLUE);
		//void   				DrawQuad2D   			(const Vect2i& pos, uint32 w, uint32 h, ETypeAlignment alignment, CTexture* texture, SRectangle2D& coordText);
		//void   				DrawQuad2D   			(const Vect2i& pos, uint32 w, uint32 h, ETypeAlignment alignment, CTexture* texture, ETypeFlip flip = NONE_FLIP);
		

	private:
		void				GetWindowRect			( HWND hwnd );
		void				SetTransform			(const D3DXMATRIX& matrix);
		void				CalculateAlignment   	(uint32 w, uint32 h, ETypeAlignment alignment, Vect2i & posFinal);
	private:
		LPDIRECT3D9			m_pD3D;
		LPDIRECT3DDEVICE9   m_pD3DDevice;
		uint16				m_uWidth;
		uint16				m_uHeight;
		bool				m_bPaintSolid;
		CColor				m_BackbufferColor_debug;
		CColor				m_BackbufferColor_release;
		float				m_PosX;
		Vect3f				m_Dir;
		Vect3f				m_Pos;
		int					m_Speed;
		float				m_Yaw;
		CFrustum			m_Frustum;
};


#endif